<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: sleep</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.0.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('group__sleep.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">sleep<div class="ingroups"><a class="el" href="group__high__level.html">High Level APIs</a> &raquo; <a class="el" href="group__pico__time.html">pico_time</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>Sleep functions for delaying execution in a lower power state.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga7abed28d3918fe2b15f8007ba6569172"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#ga7abed28d3918fe2b15f8007ba6569172">sleep_until</a> (<a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> target)</td></tr>
<tr class="memdesc:ga7abed28d3918fe2b15f8007ba6569172"><td class="mdescLeft">&#160;</td><td class="mdescRight">Wait until after the given timestamp to return.  <a href="group__sleep.html#ga7abed28d3918fe2b15f8007ba6569172">More...</a><br /></td></tr>
<tr class="separator:ga7abed28d3918fe2b15f8007ba6569172"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaeeaebd3a10e0a193022f15c8603772ba"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#gaeeaebd3a10e0a193022f15c8603772ba">sleep_us</a> (uint64_t us)</td></tr>
<tr class="memdesc:gaeeaebd3a10e0a193022f15c8603772ba"><td class="mdescLeft">&#160;</td><td class="mdescRight">Wait for the given number of microseconds before returning.  <a href="group__sleep.html#gaeeaebd3a10e0a193022f15c8603772ba">More...</a><br /></td></tr>
<tr class="separator:gaeeaebd3a10e0a193022f15c8603772ba"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae617a6842d4f3a192064c4354b88fcff"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#gae617a6842d4f3a192064c4354b88fcff">sleep_ms</a> (uint32_t ms)</td></tr>
<tr class="memdesc:gae617a6842d4f3a192064c4354b88fcff"><td class="mdescLeft">&#160;</td><td class="mdescRight">Wait for the given number of milliseconds before returning.  <a href="group__sleep.html#gae617a6842d4f3a192064c4354b88fcff">More...</a><br /></td></tr>
<tr class="separator:gae617a6842d4f3a192064c4354b88fcff"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaedc0ed51a5e908ddd660a5d279009abc"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">best_effort_wfe_or_timeout</a> (<a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> timeout_timestamp)</td></tr>
<tr class="memdesc:gaedc0ed51a5e908ddd660a5d279009abc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Helper method for blocking on a timeout.  <a href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">More...</a><br /></td></tr>
<tr class="separator:gaedc0ed51a5e908ddd660a5d279009abc"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p >Sleep functions for delaying execution in a lower power state. </p>
<p >These functions allow the calling core to sleep. This is a lower powered sleep; waking and re-checking time on every processor event (WFE)</p>
<dl class="section note"><dt>Note</dt><dd>These functions should not be called from an IRQ handler.</dd>
<dd>
Lower powered sleep requires use of the <a class="el" href="group__alarm.html#ga5092ceb879289c0a597a389f34b4815e">default alarm pool</a> which may be disabled by the PICO_TIME_DEFAULT_ALARM_POOL_DISABLED #define or currently full in which case these functions become busy waits instead.</dd>
<dd>
Whilst <em>sleep_</em> functions are preferable to <em>busy_wait</em> functions from a power perspective, the <em>busy_wait</em> equivalent function may return slightly sooner after the target is reached.</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__hardware__timer.html#gab1c72f391015ff00a96b24477aa327ee" title="Busy wait wasting cycles until after the specified timestamp using the default timer instance.">busy_wait_until()</a> </dd>
<dd>
<a class="el" href="group__hardware__timer.html#gac089d1c42bb7658bb43c798454f66e2f" title="Busy wait wasting cycles for the given (64 bit) number of microseconds using the default timer instan...">busy_wait_us()</a> </dd>
<dd>
<a class="el" href="group__hardware__timer.html#ga89b0f1dcbbdf81c92ade2930e8e38ab6" title="Busy wait wasting cycles for the given (32 bit) number of microseconds using the default timer instan...">busy_wait_us_32()</a> </dd></dl>
<h2 class="groupheader">Function Documentation</h2>
<a id="gaedc0ed51a5e908ddd660a5d279009abc" name="gaedc0ed51a5e908ddd660a5d279009abc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaedc0ed51a5e908ddd660a5d279009abc">&#9670;&nbsp;</a></span>best_effort_wfe_or_timeout()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool best_effort_wfe_or_timeout </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a>&#160;</td>
          <td class="paramname"><em>timeout_timestamp</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Helper method for blocking on a timeout. </p>
<p >This method will return in response to an event (as per __wfe) or when the target time is reached, or at any point before.</p>
<p >This method can be used to implement a lower power polling loop waiting on some condition signalled by an event (<a class="el" href="group__hardware__sync.html#ga486eada32246494118f8273a80ae6856" title="Insert a SEV instruction in to the code path.">__sev()</a>).</p>
<p >This is called <em>best_effort</em> because under certain circumstances (notably the default timer pool being disabled or full) the best effort is simply to return immediately without a __wfe, thus turning the calling code into a busy wait.</p>
<p >Example usage: </p><div class="fragment"><div class="line"><span class="keywordtype">bool</span> my_function_with_timeout_us(uint64_t timeout_us) {</div>
<div class="line">    <a class="code hl_typedef" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> timeout_time = <a class="code hl_function" href="group__timestamp.html#ga70921b9073202a54eec3494b4d19ec84">make_timeout_time_us</a>(timeout_us);</div>
<div class="line">    <span class="keywordflow">do</span> {</div>
<div class="line">        <span class="comment">// each time round the loop, we check to see if the condition</span></div>
<div class="line">        <span class="comment">// we are waiting on has happened</span></div>
<div class="line">        <span class="keywordflow">if</span> (my_check_done()) {</div>
<div class="line">            <span class="comment">// do something</span></div>
<div class="line">            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="comment">// will try to sleep until timeout or the next processor event </span></div>
<div class="line">    } <span class="keywordflow">while</span> (!<a class="code hl_function" href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">best_effort_wfe_or_timeout</a>(timeout_time));</div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// timed out</span></div>
<div class="line">}</div>
<div class="ttc" id="agroup__sleep_html_gaedc0ed51a5e908ddd660a5d279009abc"><div class="ttname"><a href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">best_effort_wfe_or_timeout</a></div><div class="ttdeci">bool best_effort_wfe_or_timeout(absolute_time_t timeout_timestamp)</div><div class="ttdoc">Helper method for blocking on a timeout.</div><div class="ttdef"><b>Definition:</b> time.c:435</div></div>
<div class="ttc" id="agroup__timestamp_html_ga70921b9073202a54eec3494b4d19ec84"><div class="ttname"><a href="group__timestamp.html#ga70921b9073202a54eec3494b4d19ec84">make_timeout_time_us</a></div><div class="ttdeci">static absolute_time_t make_timeout_time_us(uint64_t us)</div><div class="ttdoc">Convenience method to get the timestamp a number of microseconds from the current time.</div><div class="ttdef"><b>Definition:</b> time.h:136</div></div>
<div class="ttc" id="agroup__timestamp_html_ga8b7f3d602cc053f05bacceeacc257ed8"><div class="ttname"><a href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a></div><div class="ttdeci">uint64_t absolute_time_t</div><div class="ttdoc">An opaque 64 bit timestamp in microseconds.</div><div class="ttdef"><b>Definition:</b> types.h:43</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">timeout_timestamp</td><td>the timeout time </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if the target time is reached, false otherwise </dd></dl>

</div>
</div>
<a id="gae617a6842d4f3a192064c4354b88fcff" name="gae617a6842d4f3a192064c4354b88fcff"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae617a6842d4f3a192064c4354b88fcff">&#9670;&nbsp;</a></span>sleep_ms()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sleep_ms </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>ms</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Wait for the given number of milliseconds before returning. </p>
<dl class="section note"><dt>Note</dt><dd>This method attempts to perform a lower power sleep (using WFE) as much as possible.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">ms</td><td>the number of milliseconds to sleep </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga7abed28d3918fe2b15f8007ba6569172" name="ga7abed28d3918fe2b15f8007ba6569172"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga7abed28d3918fe2b15f8007ba6569172">&#9670;&nbsp;</a></span>sleep_until()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sleep_until </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a>&#160;</td>
          <td class="paramname"><em>target</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Wait until after the given timestamp to return. </p>
<dl class="section note"><dt>Note</dt><dd>This method attempts to perform a lower power (WFE) sleep</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">target</td><td>the time after which to return </td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__sleep.html#gaeeaebd3a10e0a193022f15c8603772ba" title="Wait for the given number of microseconds before returning.">sleep_us()</a> </dd>
<dd>
<a class="el" href="group__hardware__timer.html#gab1c72f391015ff00a96b24477aa327ee" title="Busy wait wasting cycles until after the specified timestamp using the default timer instance.">busy_wait_until()</a> </dd></dl>

</div>
</div>
<a id="gaeeaebd3a10e0a193022f15c8603772ba" name="gaeeaebd3a10e0a193022f15c8603772ba"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaeeaebd3a10e0a193022f15c8603772ba">&#9670;&nbsp;</a></span>sleep_us()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sleep_us </td>
          <td>(</td>
          <td class="paramtype">uint64_t&#160;</td>
          <td class="paramname"><em>us</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Wait for the given number of microseconds before returning. </p>
<dl class="section note"><dt>Note</dt><dd>This method attempts to perform a lower power (WFE) sleep</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">us</td><td>the number of microseconds to sleep </td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__hardware__timer.html#gac089d1c42bb7658bb43c798454f66e2f" title="Busy wait wasting cycles for the given (64 bit) number of microseconds using the default timer instan...">busy_wait_us()</a> </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>